/**
    Copyright (c) 2010 yakiimo02
    Distributed under the New BSD License.
    See included license.txt or http://www.yakiimo3d.com/NewBSDLicense.txt
**/

#pragma once

#include "DataBufferDX11.h"
#include "reference/SmallPtCPU.h"
#include "optimized/SmallPtCPU_MT.h"

enum SmallPtMode 
{
    SMALLPT_MODE_CPU_REF,                    // reference cpu implementation
    SMALLPT_MODE_CPU_OPT                     // optimized cpu implementation
};

/**
    @brief   Manages the different smallpt implementations.
    @author  yakiimo02
    @date    2010/08
*/
class SmallPtMgr
{
public:
    SmallPtMgr();
    ~SmallPtMgr();

    HRESULT OnCreateDevice( ID3D11Device* pd3dDevice );
    HRESULT OnResizedSwapChain( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,  bool bForceRecreate );
    void    OnFrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext,
                                  double fTime, float fElapsedTime );
    void    OnDestroyDevice();
    
    inline void SetMode( const SmallPtMode mode ) { m_mode = mode; }

    inline SmallPtMode            GetMode() const { return m_mode; }
    inline DataBufferDX11*        GetpDataBufferDX11() { return &m_dataBufferDX11; }

protected:
    REF::SmallPtCPU       m_cpu;                   // cpu non-multithreaded
    OPT::SmallPtCPU_MT    m_cpuMT;                 // cpu multithreaded 
    SmallPtMode           m_mode;                  // smallpt implementation type
    DataBufferDX11        m_dataBufferDX11;        // manages uav, srv for the cpu output buffer
    DXGI_SURFACE_DESC     m_backBufferDesc;        // backbuffer width, height
};

extern SmallPtMgr    g_smallPtMgr;
